package cn.jizi.bshisy.controller;

import cn.jizi.bshisy.Md.MD;
import cn.jizi.bshisy.entity.DoctorCase;
import cn.jizi.bshisy.service.DoctorCaseSevice;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/doctorcase")
public class DoctorCaseController {

    @Resource
    private DoctorCaseSevice doctorCaseSevice;

    //登录
    @ApiOperation(value="登录", notes="登录")
    @GetMapping("/dolog")
    public String index(String name,String pwd, HttpServletRequest request){
        DoctorCase doctorCase = new DoctorCase();
        doctorCase.setDname(name);
        doctorCase.setPassword(MD.getMD5(pwd));
        DoctorCase doctorCase1 = doctorCaseSevice.getSeleDoctor(doctorCase);
        if (doctorCase1!=null){
            return  "登录成功";
        }else{
            return"登录失败!";
        }
    }

    //注册账户
    @ApiOperation(value="注册账户", notes="注册账户")
    @PostMapping("/zhuce")
    public String zhuce(DoctorCase doctorCase){
        String pwd =MD.getMD5(doctorCase.getPassword());
        doctorCase.setPassword(pwd);
        int sum = doctorCaseSevice.getAddDoctorCase(doctorCase);
        if(sum>0){
            return "添加成功";
        }else {
            return "添加失败";
        }
    }
}
